//
//  ST_PinterestFilterOptionView.swift
//  btvideo
//
//  Created by mac on 2020/5/29.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift

class ST_PinterestFilterOptionView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        self.addSubview(info_label)
        self.addSubview(content_label)
        self.addSubview(nav_image_view)
        
        info_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(25)
            make.centerY.equalToSuperview()
        }
        content_label.snp.makeConstraints { (make) in
            make.left.equalTo(info_label.snp.right).offset(10)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-35)
        }
        nav_image_view.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-15)
        }
        
        self.addSubview(click_btn)
        click_btn.snp.makeConstraints { (make) in
            make.top.right.bottom.equalToSuperview()
            make.width.equalTo(100)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    fileprivate lazy var info_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
//        control.numberOfLines = 0
        control.textAlignment = .left
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
//        control.numberOfLines = 0
        control.textAlignment = .right
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var nav_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("mycenter_icon_下一页")
        return control
    }()
    
    
    fileprivate lazy var click_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.addTarget(self, action: #selector(click_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
//    MARK: - Event
    var pushOptionClosure:((PinterestFilterOptionModel)->())?
    
    @objc func click_handle(){
        
        
        guard let m = self.model else {
            return
        }
        
        pushOptionClosure?(m)
        
    }
    
//    MARK: - Bind Model
    var model:PinterestFilterOptionModel?
    func bind(model:PinterestFilterOptionModel){
        
        self.model = model
        
        self.info_label.text = model.keyString
        self.content_label.text = model.value
        
    }
}




class PinterestStatureFilterOptionView: ST_PinterestFilterOptionView {
    
    override func bind(model: PinterestFilterOptionModel) {
        
        self.model = model
        
        self.info_label.text = model.keyString
        self.content_label.text = model.minValue.string + "cm" + "-" + model.maxValue.string + "cm"
    }
    
    
}



//MARK: -
class PinterestFilterSwitchControl: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        self.addSubview(info_label)
        self.addSubview(select_control)
        
        info_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(25)
            make.centerY.equalToSuperview()
        }
        
        select_control.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-20)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    fileprivate lazy var info_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
//        control.numberOfLines = 0
        control.textAlignment = .left
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var select_control:UISwitch = {
       let control = UISwitch()
         control.onTintColor = UIColor.init(hex: 0xFEC207)
         control.backgroundColor = UIColor.init(hex: 0xACB4C0)
         control.cornerRadius = 16
        control.addTarget(self, action: #selector(vale_change_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
//    MARK: - Event
    var pushOptionClosure:((PinterestFilterOptionModel)->())?
    
    @objc func vale_change_handle(){
        
        
        guard let m = self.model else {
            return
        }
         
        m.isOn = select_control.isOn
        
        pushOptionClosure?(m)
        
    }
    
//    MARK: - Bind Model
    fileprivate var model:PinterestFilterOptionModel?
    func bind(model:PinterestFilterOptionModel){
        
        self.model = model
        
        self.info_label.text = model.keyString
        self.select_control.isOn = model.isOn
        
    }
}



